package cn.etc;



import org.apache.hadoop.io.Writable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
     * 本案列的功能：演示自定义类型如何实现hadoop的序列化接口
     * 该类一定要保留空参构造函数
     * write 方法中输出字段二进制数据的顺序 要与 readFields方法读取数据的顺序一致
     *
     */
    public class FlowBean implements Writable {
        private int upFlow;
        private int dFlow;
        private String phone;
        private int amountFlow;

        public FlowBean(long upFlow, long dFlow){}

        public FlowBean(String phone,int upFlow,int dFlow){
            this.phone = phone;
            this.dFlow = dFlow;
            this.upFlow = upFlow;
            this.amountFlow = dFlow + upFlow;
        }


    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(int upFlow) {
        this.upFlow = upFlow;
    }

    public int getdFlow() {
        return dFlow;
    }

    public void setdFlow(int dFlow) {
        this.dFlow = dFlow;
    }

    public int getAmountFlow() {
        return amountFlow;
    }

    public void setAmountFlow(int amountFlow) {
        this.amountFlow = amountFlow;
    }
    /**
     * hadoop 系统在序列化该类的对象时要调用的方法
     *
     */
    public void write(DataOutput dataOutput) throws IOException{
        dataOutput.writeInt(upFlow);
        dataOutput.writeUTF(phone);
        dataOutput.writeInt(dFlow);
        dataOutput.writeInt(amountFlow);

    }

    /**
     * hadoop 系统在反序列化该类的对象时要调用的方法
     *
     */

    public void readFields(DataInput in) throws IOException {
        this.upFlow = in.readInt();
        this.phone = in.readUTF();
        this.dFlow = in.readInt();
        this.amountFlow = in.readInt();
    }

    @Override
    public String toString() {
        return this.phone + ","+ this.upFlow +"," + this.dFlow + ","+ this.amountFlow;
    }
}
